package com.wt.admin.controller.language;


import com.aizuda.easy.security.domain.Rep;
import com.aizuda.easy.security.domain.Req;
import com.wt.admin.code.language.QA2200;
import com.wt.admin.code.language.Tagging2100;
import com.wt.admin.config.aspect.annotation.LogAno;
import com.wt.admin.domain.dto.language.ClassTrainingDTO;
import com.wt.admin.domain.dto.language.QADTO;
import com.wt.admin.domain.dto.language.QATrainingDTO;
import com.wt.admin.domain.dto.language.SentenceConfigDTO;
import com.wt.admin.domain.vo.language.*;
import com.wt.admin.domain.vo.sys.UserVO;
import com.wt.admin.service.language.LanguageProxyService;
import com.wt.admin.util.AssertUtil;
import com.wt.admin.util.PageUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("qa")
public class QAController {

    @Resource
    private LanguageProxyService languageProxyService;

    @LogAno(name = "添加问答")
    @PostMapping("add")
    public Rep<QAVO> add(@RequestBody Req<QADTO, UserVO> req){
        return Rep.ok(languageProxyService.getQAService().add(req.getData()));
    }

    @LogAno(name = "问答列表")
    @PostMapping("list")
    public Rep<QAListVO> list(@RequestBody Req<PageUtil.PageDTO<QADTO>, UserVO> req){
        return Rep.ok(languageProxyService.qaList(req.getData()));
    }

    @LogAno(name = "删除问答")
    @PostMapping("del")
    public Rep<QAVO> del(@RequestBody Req<QADTO, UserVO> req){
        return Rep.ok(languageProxyService.getQAService().del(req.getData()));
    }

    @LogAno(name = "编辑问答")
    @PostMapping("edit")
    public Rep<QAVO> edit(@RequestBody Req<QADTO, UserVO> req){
        return Rep.ok(languageProxyService.getQAService().edit(req.getData()));
    }

    @LogAno(name = "训练样本")
    @PostMapping("qaTraining")
    public Rep<ClassificationVO> qaTraining(@RequestBody Req<QATrainingDTO, UserVO> req){
        AssertUtil.List.isEmpty(req.getData().getId(), QA2200.CODE_2205);
        languageProxyService.qaTraining(req.getData(),req.getUser());
        return Rep.ok();
    }

    @LogAno(name = "测试样本")
    @PostMapping("qaTestTraining")
    public Rep<QAParseSentenceVO> qaTestTraining(@RequestBody Req<String, UserVO> req){
        return Rep.ok(languageProxyService.qaTestTraining(req.getData(),req.getUser()));
    }

    @LogAno(name = "查询配置")
    @PostMapping("findConfig")
    public Rep<SentenceConfigVO> findConfig(@RequestBody Req<SentenceConfigDTO, UserVO> req){
        req.getData().setTag("qa");
        return Rep.ok(languageProxyService.getSentenceConfigService().findConfig(req.getData(),req.getUser()));
    }

    @LogAno(name = "更新配置")
    @PostMapping("updateConfig")
    public Rep<SentenceConfigVO> updateConfig(@RequestBody Req<SentenceConfigDTO, UserVO> req){
        req.getData().setTag("qa");
        return Rep.ok(languageProxyService.getSentenceConfigService().updateConfig(req.getData(),req.getUser()));
    }

}
